package proxy;

import org.springframework.cglib.core.SpringNamingPolicy;
import org.springframework.cglib.proxy.CallbackFilter;import org.springframework.cglib.proxy.Enhancer;import org.springframework.cglib.proxy.FixedValue;
import org.springframework.cglib.proxy.NoOp;

import java.io.IOException;
import java.lang.reflect.Method;

public class Main {

    public static void main(String[] args) throws IOException {
        Hello target = new Hello();

        // 增强器
        Enhancer enhancer = new Enhancer();
        // 设置父类
        enhancer.setSuperclass(target.getClass());
        // 设置处理器
//        enhancer.setCallback(new HelloInvocationHandler(target));
        enhancer.setCallback(new NoOp() {
//            @Override
//            public Object loadObject() throws Exception {
//                return System.currentTimeMillis();
//            }
        });

        // 创建代理对象 class Hello$$EnhancerByCGLIB$$512b9276 ex Hello impl net.sf.cglib.proxy.Factory
        Hello hello = (Hello) enhancer.create();

        //调用代理对象方法
        hello.say("asd");
        System.out.println(hello.say("asd"));
        System.out.println(hello.say("asd"));
        System.out.println(hello.say("asd"));

        ProxyUtil.printExtend(hello);

    }


}
